package com.hee.erp.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hee.erp.modules.entity.BusCustomerVisit;
import com.hee.erp.modules.entity.SysUser;
import com.hee.erp.modules.mapper.BusCustomerVisitMapper;
import com.hee.erp.modules.service.IBusCustomerVisitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hee.erp.modules.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author weizehong
 * @since 2022-04-16
 */
@Service
@Transactional
public class BusCustomerVisitServiceImpl extends ServiceImpl<BusCustomerVisitMapper, BusCustomerVisit> implements IBusCustomerVisitService {

    @Autowired
    ISysUserService userService;
    @Override
    public List<BusCustomerVisit> getListByCustomerId(String customerId) {

        LambdaQueryWrapper<BusCustomerVisit> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusCustomerVisit::getCustomerId, customerId);
        List<BusCustomerVisit> list = this.list(queryWrapper);
        for (BusCustomerVisit visit : list) {
            SysUser user = userService.getById(visit.getVisitorId());
            visit.setVisitorName(user.getUserName());
        }

        return list;
    }
}
